<template>
  <div class="xq">
    <div class="head">
      <span @click="onClickLeft"> 〈 返回</span>
      <span>排名</span>
      <span></span>
    </div>
    <header>
      <input type="text" placeholder="搜索你想知道的一切排名" @click="goSearch" />
    </header>
    <div class="nr">
      <select name="全球" id="">
        <option value="" v-for="(item, index) in classDrop" :key="index">
          {{ item.name }}
        </option>
      </select>
    </div>
    <div class="ph">
      <span>排名</span>
      <span style="margin-left: 4.7rem">名称</span>
      <div class="v">
        <ul>
          <li v-for="(item, index) in classDetail" :key="index">
            <span
              style="
                width: 1.5rem;
                height: 1.5rem;
                border-radius: 50%;
                color: rgb(201, 129, 250);

                text-align: center;
                font-size: 0.5rem;
              "
              >{{ index }}</span
            >
            <span
              style="
                width: 12rem;
                height: 1.5rem;
                color: #999;
                border-radius: 0.5rem;
              "
              >{{ item.name }}</span
            >
            <span
              style="
                width: 4rem;
                height: 1.5rem;
                background: #eee;
                border-radius: 0.5rem;
              "
              @click="db(item)"
            >
              对比+</span
            >
          </li>
        </ul>
      </div>
    </div>
    <div class="xd">
      <van-tabs v-model="activeName">
        <van-tab title="今日精选"> 无 </van-tab>
        <van-tab title="一日内精选"> 无 </van-tab>
        <van-tab title="一周内精选">无</van-tab>
        <van-tab title="一月内精选">无</van-tab>
      </van-tabs>
    </div>
    <button
      style="
        width: 23rem;
        height: 2.5rem;
        background: blue;
        border-radius: 1rem;
        color: #eee;
        font-size: 1.1rem;
        position: fixed;
        bottom: 0.5rem;
        left: 0.2rem;
      "
      @click="d"
    >
      对比
    </button>
    <div class="len">
      {{ data.car.length }}
    </div>
    <div class="db" v-if="data.index == 0" >
      <div class="w">
        <span>排名</span>
        <span style="margin-left: 0.7rem">名称</span>
        <span style="margin-left: 7rem
                 " @click="dc">---</span>
        <div class="l">
          <ul>
            <li v-for="(item, index) in data.car" :key="index">
              <span
                style="
                  width: 1.5rem;
                  height: 2.5rem;
                  border-radius: 50%;
                  color: rgb(201, 129, 250);
                  text-align: center;
                  font-size: 0.5rem;
                "
                >{{ index }}</span
              >
              <span
                style="
                  width: 12rem;
                  height: 2.5rem;
                  color: #999;
                  border-radius: 0.5rem;
                "
                >{{ item.name }}</span
              >
              <span
                style="
                  width: 4rem;
                  height: 1.5rem;
                  float:right;
                  margin-right:1rem;
                  background: #eee;
                "
                @click="qx(index)"
              >
                取消-</span
              >
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getClassDropList, getClassDetail } from "@/api/classify";
import { defineComponent, computed, reactive } from "vue";
import { useStore } from "vuex";
import {useRouter} from 'vue-router'
export default defineComponent({
  setup(props, context) {
    function onClickLeft() {
      console.log(1);
      this.$router.go(-1);
    }
    let router = useRouter();
    let data = reactive({
      index: 1,
      car: [],
    });
    function db(item) {
      console.log(item);
      if (data.car.indexOf(item)) {
        data.car.push(item);
        console.log(data.car);
      }
    }
    function d() {
      data.index = 0;
    }
    function dc() {
      data.index = 1;
    }
    function qx(id) {
      data.car.splice(id,1)
    }
    function goSearch() {
      router.push("/search");
    }
    let store = useStore();
    return {
      qx,
      data,
      dc,
      d,
      goSearch,
      db,
      onClickLeft,
      classDrop: computed(() => store.state.Classify.classDrop),
      classDetail: computed(() => store.state.Classify.classDetail),
    };
  },
});
</script>

<style>
.len {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  text-align: center;
  line-height: 2.2rem;
  background: rgb(240, 15, 15);
  color: #eee;
  position: fixed;
  bottom: 2.3rem;
  right: 0.5rem;
}
.db {
  position: fixed;
  top: 0;
  z-index: 9999;
  width: 100%;
  height: 100%;
  background: rgba(46, 43, 43, 0.5);
  
  /* text-align: center; */
}
.db .w {
  overflow: hidden;
  overflow-y: scroll;
  width: 20rem;
  height: 15rem;
  position: relative;
  top: 10rem;
  left: 1.5rem;
  background: rgb(245, 240, 240);
}

.xq {
  width: 100%;
  height: 100%;
}
.xd dl {
  text-align: center;
}
.head {
  font-size: 1rem;
  width: 100%;
  height: 2.5rem;
  line-height: 2.5rem;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #eee;
}
.nr {
  width: 100%;
}
.nr select {
  width: 4.4rem;
  margin: 0.5rem;
  border-radius: 0.5rem;
}
.ph {
  width: 100%;
  height: 21rem;
  overflow: hidden;
  margin-top: 0.5rem;
}
.v {
  margin-top: 0.5rem;
  width: 100%;
  height: 100%;
  overflow-y: scroll;
}
.ph {
  margin-top: 0.5rem;
}
.ph > span {
  margin: 1.5rem;
}
.ph ul li {
  margin-top: 0.5rem;
  display: flex;
  height: 2rem;
  /* text-align: center; */
}
.ph ul li span {
  line-height: 1.6rem;
  text-align: center;
  margin-left: 1.7rem;
}
.w > span {
  margin: 1.5rem;
}
.l ul li span{
  line-height: 2rem;
  text-align: center;
  margin-left: 2rem;
}
header {
  display: flex;
  justify-content: center;
  align-items: center;
}
header input {
  width: 95%;
  height: 1.6rem;
  background: #eee;
  border-radius: 1rem;
  border: 0;
  margin-top: 0.5rem;
  font-size: 0.7rem;
  text-indent: 0.5rem;
}
</style>
